#!/usr/bin/env python
#coding=utf-8
import yyWeb
import parse
import threading
import wx

class CodeThread(threading.Thread):  
    def __init__(self, window, proxy, inviteUrl):
        threading.Thread.__init__(self)
        self.window = window
        self.proxy = proxy
        self.inviteUrl = inviteUrl
    
    def run(self): 
        wx.CallAfter(self.window.messageCall, u'正在获取验证码')
        self.web = yyWeb.YYWeb(proxy=self.proxy, logfile='', interval_time=2)
        f = self.web.retrieveImg(self.inviteUrl['id'], self.inviteUrl['code'])
        imgSrc = parse.parseRetrieveImg(f)
        
        if imgSrc:
            url = 'http://www.yy365.com/%s' % imgSrc
            f = self.web.getCodeImg(url, self.inviteUrl['id'], self.inviteUrl['code'])
            wx.CallAfter(self.window.codeCall, f, self.web)
            wx.CallAfter(self.window.messageCall, u'获取验证码成功')
        else:
            wx.CallAfter(self.window.messageCall, u'获取验证码地址失败')
            
